package com.hospital.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.model.YaoName;
import com.hospital.util.DbUtil;
@WebServlet("/manage/YaoNameInfoServlet")
public class YaoNameInfoServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {//药品名称信息管理Servlet
		// TODO Auto-generated method stub
		String method = request.getParameter("method");
		if ("add".equals(method)) {
			YaoName yaoName = new YaoName();
			Connection conn = null;
			PreparedStatement stmt = null;
			ResultSet rs = null;
			String mname = request.getParameter("mname").trim();
			String money = request.getParameter("money").trim();
			String sql = "insert into t_medicinename(mname , money,addtime) values('"
					+ mname +"', '" + money +"', '" + yaoName.getDate() + "')";
			DbUtil.add_modify(sql);
		} else if ("del".equals(method)) {
			String[] id = request.getParameterValues("selectFlag");
			DbUtil.del("t_medicinename", id);
		} else if ("modify".equals(method)) {
			int id = Integer.parseInt(request.getParameter("id"));
			String mname = request.getParameter("mname").trim();
			String money = request.getParameter("money").trim();
			String sql = "update t_medicinename set mname = '" + mname + "', money = '" + money + "' where id = " + id;
			DbUtil.add_modify(sql);
		}
		
		request.getRequestDispatcher("/manage/yaoname_info_manage.jsp").forward(request, response);
	}
	
}
